<template>
	<view>
		<view v-if="isLoading == true"><image class="loading" src="https://huajia-online-1316192331.cos.ap-guangzhou.myqcloud.com/static/loading-1.gif"></image></view>
		<view v-if="isLoading == false">
			<uni-list v-for="one in list">
				<uni-list :border="true">
					<!-- 头像显示角标 -->
					<uni-list-chat
						:title="one.name"
						:avatar="one.photo"
						note="进入咨询"
						:time="date"
						badge-positon="left"
						link="navigateTo"
						:to="'../chat/chat?id=' + one.id + '&hisAvatar=' + one.photo + '&to_name=' + one.name"
					></uni-list-chat>
					</uni-list>
		</uni-list>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			haveNew: false,
			date: new Date(),
			isLoading:true
		};
	},
	onLoad() {
		let that = this;
		that.ajax(that.url.getAcceptId, 'GET', null, function(resp) {
			that.list = resp.data.result;
			console.log(that.list.length);
		});
		this.timer = null;
		// this.startPolling();
		setTimeout(function(resp) {
					that.isLoading = false
				}, 400);
	},
	onUnload() {
		clearInterval(this.timer);
		this.timer = null;
	},
	methods: {
		startPolling() {
			let that = this;

			this.timer = setInterval(() => {
				//轮询操作
				for (let i = 0; i < that.list.length; i++) {
					that.ajax(that.url.haveNew, 'POST', { senderId: that.list[i].id }, function(resp) {
						that.haveNew = resp.data.result;
						if (that.haveNew == true) {
							that.list[i].haveNew;
						}
						console.log(that.list[i].haveNew);
					});
				}
			}, 4000); //轮询间隔为1秒
		}
	}
};
</script>

<style lang="less">
@import url('friend_list.less');
</style>
